<template>
  <div p-5>
    <DynamicTable
      :data-request="loadTableData"
      :columns="columns"
      bordered
      :scroll="{
        y: 'calc(100vh - 330px)',
      }"
    >
    </DynamicTable
  ></div>
</template>
<script setup lang="ts">
  import { useTable } from '@/components/core/dynamic-table';
  import { baseColumns, type TableColumnItem } from './columns';
  import { approveList } from '@/api/administrative';
  import router from '@/router';
  defineOptions({
    name: 'approve',
  });

  const [DynamicTable, dynamicTableInstance] = useTable();

  /**
   * 表格数据
   */

  const loadTableData = async (params): Promise<API.TableListResult> => {
    const data = await approveList(params);
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          list: data,
          ...params,
        });
      }, 500);
    });
  };

  const columns: TableColumnItem[] = [
    ...baseColumns,
    {
      title: '操作',
      width: 40,
      dataIndex: 'ACTION',
      align: 'center',
      fixed: 'right',
      actions: ({ record }) => [
        {
          label: '审批',
          ifShow: record.reviewStatus === 1,
          onClick: () =>
            router.push({
              path: '/administrative/accraditation',
              query: { progressId: record.progressId, id: record.id },
            }),
        },
        {
          label: '查看',
          ifShow: record.reviewStatus === 2 || record.reviewStatus === 3,
          onClick: () =>
            router.push({
              path: '/administrative/approveView',
              query: { id: record.id },
            }),
        },
      ],
    },
  ];
</script>

<style lang="less" scoped></style>
